<template>
  <admin-layout>
    <el-table :data="userData" style="width: 100%" empty-text="暂无数据" v-loading="isLoading">
      <el-table-column label="日期">
        <template #default="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名">
        <template #default="scope">
          <el-popover effect="light" trigger="hover" placement="top">
            <template #default>
              <p>姓名: {{ scope.row.name }}</p>
              <p>住址: {{ scope.row.address }}</p>
            </template>
            <template #reference>
              <div class="name-wrapper">
                <el-tag size="medium">{{ scope.row.name }}</el-tag>
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </admin-layout>
</template>

<script>
  // import logo from "../assets/logo.png"
  import {
    mapActions,
    mapState
  } from "vuex"
  import AdminLayout from '../../layout/AdminLayout.vue';
  export default {
    components: {
      AdminLayout
    },
    name: "Home",
    computed: {
      ...mapState("db", ["userData"])
    },
    data() {
      return {
        // logo,
        isLoading: false,
        activeIndex: '1',
        activeIndex2: '1'
      }
    },
    async created() {
      this.isLoading = true;
      try {
        await this.getList();
      } catch (e) {
        // this.isLoading = false
        this.$message.error("网络错误");
      } finally {
        this.isLoading = false;
      }
    },
    methods: {
      ...mapActions("db", ["getList"]),
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      handleSelect(key, keyPath) {
        console.log(key, keyPath);
      }
    }
  }
</script>
<style lang="less" scoped>
  .el-header {
    background-color: #545c64;
  }

  .el-aside {
    background-color: #8c9792;
  }

  .el-main {
    height: calc(100vh - 60px);
  }
</style>